﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<blockquote class="layui-elem-quote">
    基础信息表和自由流程不能设置流程步骤；如需删除流程进入录入表管理页面，删除录入表便可删除对应流程
</blockquote>
<fieldset class="table-fieldset" id="searchfield">
    <div style="margin: 5px 5px 5px 5px">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="text" name="key" id="key" placeholder="关键字" class="layui-input">
                </div>
                <div class="layui-inline">
                    <button type='button' class='layui-btn layui-btn-normal' id='search' lay-submit lay-filter='search'><i class='layui-icon layui-icon-search'></i></button> <button type='reset' class='layui-btn layui-btn-primary'><i class='layui-icon layui-icon-refresh'></i></button>
                </div>
            </div>
        </form>
    </div>
</fieldset>
<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
<script>
    layui.use(["table", "form", "exLayer", "exUtils", "miniPage"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let miniPage = layui.miniPage;

        let $ = layui.$;
        var openWH = miniPage.getOpenWidthHeight();

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysFlow/Flow/GetList",
            limit: 100,
            toolbar: "#toolbarTpl",
            defaultToolbar: [{ title: '搜索', layEvent: 'searchShow', icon: 'layui-icon-search' }, 'exports'],
            page: true,

            cols: [[
                { field: "FlowId", title: "编码", sort: true },
                { field: "FlowName", title: "名称", sort: true },
                { field: "FlowType", title: "类型", sort: true, width: 100, templet: "#FlowType" },
                { title: "操作", width: 200, align: "center", fixed: "right", templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        form.on("submit(search)", function (data) {
            ThisTable.reload({
                url: "/SysFlow/Flow/GetList?key=" + $("#key").val(),
                page: { curr: 1 }
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
                case "refresh":
                    refresh();
                    break;
                case "searchShow":
                    searchShow();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data.FlowId, data.FlowName);
                    break;
                case "flowprcs":
                    flowPrcs(data.FlowId, data.FlowName, data.TbId, data.FlowType);
                    break;
            }
        });

        function refresh() {
            ThisTable.reload({
            });
        }

        function edit(id, name) {
            exLayer.open(name + "-编辑", "/SysFlow/Flow/Edit?id=" + id, '100%', '100%', '0px', '0px', null, null);
        }

        function flowPrcs(id, name, tbid, type) {
            if (type == "0") {
                exLayer.yellowSighMsg("基础信息录入表不能设置流程步骤");
                return false;
            }
            if (type == "2") {
                exLayer.yellowSighMsg("自由流程无需设置流程步骤");
                return false;
            }
            exLayer.open(name + "-流程步骤", "/SysFlow/FlowPrcs/List?id=" + id + "&tbid=" + tbid, openWH[0] + 'px', openWH[1] + 'px', openWH[2] + 'px', openWH[3] + 'px', null, null);
        }

        function searchShow() {
            var display = $('#searchfield').css('display');
            if (display == 'none') {
                $("#searchfield").show();
            }
            else {
                $("#searchfield").hide();
            }
        }
    });
</script>
<script type='text/html' id='FlowType'>
    {{#  if(d.FlowType == 1){ }}
    固定流程
    {{#  } }}
    {{#  if(d.FlowType == 2){ }}
    自由流程
    {{#  } }}
    {{#  if(d.FlowType == 0){ }}
    无流程
    {{#  } }}
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id="edit">基本属性</a>
    {{#  if(d.FlowType == '1'){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="flowprcs" id="flowprcs">流程步骤</a>
    {{#  }else{ }}
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="flowprcs" id="flowprcs"><i class="fa fa-ban"></i>流程步骤</a>
    {{#  } }}
</script>